#!/bin/bash

ERROR=0
PORT=$1
cd $(dirname "$0")
. ./common.sh

if [ -z "$PORT" ] ; then
    echo 'Check port function is need a paramters';
    ERROR=1;
else
    portAway=`netstat -ptan | grep -w 'LISTEN' | grep :${PORT} | wc -l`;
    if [ $portAway -ne 0 ]; then
     	echo 'Port '${PORT}' already exists';
        ERROR=0;    
    else
        ERROR=1;
    fi    
fi

exit $ERROR


